import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class OrderLock {
    private final Set<Long> orderIdSet;

    public OrderLock() {
        orderIdSet = Collections.synchronizedSet(new HashSet<>());
    }

    public synchronized boolean getLock(long orderId) {
        if (orderIdSet.contains(orderId)) {
            return false;
        } else {
            orderIdSet.add(orderId);
            return true;
        }
    }

    public synchronized void releaseLock(long orderId) {
        orderIdSet.remove(orderId);
    }

    public synchronized void releaseAllLocks() {
        orderIdSet.clear();
    }

    public synchronized boolean isLocked(long orderId) {
        return orderIdSet.contains(orderId);
    }

    public synchronized int getLockCount() {
        return orderIdSet.size();
    }

    public synchronized Set<Long> getLockedOrderIds() {
        return orderIdSet;
    }
}
